package com.zrrd.reggie.config;

import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//标注当前类是配置类
@Configuration
public class MybarisPlusConfig {

    //配置Plus的拦截器
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        //创建mp的拦截器对象
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //给拦截器对象添加一个分页插件拦截器
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
        //返回mp的拦截器对象
        return interceptor;
    }

    //全局设置
    @Bean
    public GlobalConfig globalConfig() {
        GlobalConfig globalConfig = new GlobalConfig();
        GlobalConfig.DbConfig dbConfig = new GlobalConfig.DbConfig();
        // 逻辑删除标识值（已删除）
        dbConfig.setLogicDeleteValue("1");
        // 逻辑未删除标识值（未删除）
        dbConfig.setLogicNotDeleteValue("0");
        globalConfig.setDbConfig(dbConfig);
        return globalConfig;
    }
}
